package com.monkey.thread;

import java.util.concurrent.TimeUnit;

/**
 * @Author MonkeyBrother
 * @Date 2020/12/17 23:26
 * @Desc
 **/
public class Account {
    static int money = 100;

    public void outMoney(int count) throws InterruptedException {
        synchronized (this) {
            while (money < 100) {
                System.out.println("卡里没有钱了！");
                this.notifyAll();

                this.wait();

            }
            System.out.println("开始取钱！");
            while (money >= 100) {
                money = money - count;
                System.out.println("小明取了100 元之后还剩余：" + money);

                Thread.sleep(1000);

            }
        }
    }

    public void addMoney(int count) throws InterruptedException {
        synchronized (this) {
            while (money < 100) {
                money = money + count;
                System.out.println(money);
                this.notifyAll();
                this.wait();

            }

        }
    }

}
